
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>积分管理</title>
<link rel="stylesheet" type="text/css"
	th:href="@{/static/css/normalize.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/static/css/demo.css}" />
<link rel="stylesheet" type="text/css"
	th:href="@{/static/css/bootstrap.min.css}" />
<link rel="stylesheet" type="text/css"
	th:href="@{/static/css/integral.css}" />
<style>
.container-width {
	max-width: 400px;
}

.form-group {
	margin: 10px auto;
}

.form {
	margin-top: 40px;
}

.label {
	color: #777;
	font-size: 12px;
}
</style>
</head>
<body>
	<div class="r-top">
		<div class="mytitile hidden-xs hidden-sm">
			<div class="img">
				<i class="glyphicon glyphicon-calendar"></i>
			</div>
			<div class="detail-info">
				<span class="p1">积分详情</span><br /> <span class="p2"><i
					class="glyphicon glyphicon-grain"></i>&nbsp;各同学每学期积分情况汇总，每学期更新</span>
			</div>
		</div>
		<form th:action="@{/integral/list.do}" method="post"
			th:object="${voQueryVoIntegral}">
			<div class="input-group">
				<div class="e-input">
					<input type="text" placeholder="输入学号、姓名查询" name="voStuIdAndName"
						th:value="${voStuIdAndName}" />
				</div>
				<div class="e-input">
					<select name="voClass" class="choice">
						<c th:if="${voClass == ''}">
						<option value="">--请选择班级--</option>
						</c>
						<c th:if="${voClass != ''}">
						<option th:value="${voClass}" th:text="${voClass}"></option>
						<option value="">--请选择班级--</option>
						</c>
						<option th:each="class:${allClass}" th:text="${class.className}"></option>
					</select>
				</div>
				<div class="e-input">
					<select name="voClub" class="choice">
						<c th:if="${voClub == ''}">
						<option value="">--请选择部室--</option>
						</c>
						<c th:if="${voClub != ''}">
						<option th:value="${voClub}" th:text="${voClub}"></option>
						<option value="">--请选择部室--</option>
						</c>
						<option th:each="club:${allRoom}" th:text="${club.clubroomName}"></option>
					</select>
				</div>
				<div class="e-input last">
					<select name="voSemester" class="choice">
						<c th:if="${voSemester == ''}">
						<option value="">--请选择学期--</option>
						</c>
						<c th:if="${voSemester != ''}">
						<option th:value="${voSemester}" th:text="${voSemester}"></option>
						<option value="">--请选择学期--</option>
						</c>
						<option th:each="semester:${allSemester}"
							th:text="${semester.semesterName}"></option>
					</select>
				</div>
				<div class="search">
					<button type="submit">
						<i class="glyphicon glyphicon-search"></i>
					</button>
				</div>
			</div>
		</form>
	</div>
	<div class="r-main">
		<c
			th:if="${session.user.role} == administrator or ${session.user.role} == admin">
		<div class="option">
			<span class="o-right"> <a
				th:href="@{/integral/export.do?(voStuIdAndName=${voStuIdAndName},
			voClass=${voClass},voClub=${voClub},voSemester=${voSemester})}"><i
					class="glyphicon glyphicon-download-alt"></i><span>下载</span></a>
			</span>
		</div>
		</c>

		<div class="table-responsive">
			<table class="table table-striped table-hover">
				<thead>
					<tr>
						<th><input type="checkbox" id="all" /></th>
						<td>ID</td>
						<td>姓名</td>
						<td>学号</td>
						<td>班级</td>
						<td>分数</td>
						<td>原因</td>
						<td>时间</td>
						<td>部室</td>
						<td>学期</td>
						<td>录入时间</td>
						<td>修改时间</td>
						<td>录入者</td>
						<c
							th:if="${session.user.role} == administrator or ${session.user.role} == admin">
						<td>操作</td>
						</c>
					</tr>
				</thead>
				<tbody>
					<tr th:each="prod : ${pageInfo.list}">
						<td class="first"><input type="checkbox" /></td>
						<td th:text="${prod.integralId}"></td>
						<td th:text="${prod.studentName}"></td>
						<td th:text="${prod.studentId}"></td>
						<td th:text="${prod.grades}"></td>
						<td th:text="${prod.score}"></td>
						<td th:text="${prod.reason}"></td>
						<td th:text="${prod.time}"></td>
						<td th:text="${prod.clubroom}"></td>
						<td th:text="${prod.intSemester}"></td>
						<td th:text="${prod.creatime}"></td>
						<td th:text="${prod.updateTime}"></td>
						<td th:text="${prod.name}"></td>
						<c
							th:if="${session.user.role} == administrator or ${session.user.role} == admin">
						<td><a href="javascript:void(0)" class="edit"><img
								th:src="@{/static/img/edit.png}" alt="编辑" width="20px"
								height="20px" /></a> <span class="mid">|</span> <a
							href="javascript:void(0)" class="delete"><img
								th:src="@{/static/img/delete.png}" width="20px" height="20px" /></a>
						</td>
						</c>
					</tr>
				</tbody>
			</table>
		</div>
		
		<!-- 显示分页信息 -->
		<div class="recode">
			<!-- 分页文字信息  -->
			<p>
				当前 <span th:text="${pageInfo.pageNum}"></span>页,总<span
					th:text="${pageInfo.pages }"></span> 页,总 <span
					th:text="${pageInfo.total}"></span> 条记录
			</p>
		</div>
		
		<!-- 分页条信息 -->
		<div class="page">
			<ul class="allpage">
			
				<li><a th:href="@{${adss}+'?pn=1'}">首页</a></li>
				
				<li th:if="${pageInfo.hasPreviousPage}"><a
					th:href="@{${adss}+'?pn='+${pageInfo.pageNum-1}}">&laquo;</a></li>
					
					
				<span th:each="page_Num : ${pageInfo.navigatepageNums}"> 
				
				<li th:if="${page_Num == pageInfo.pageNum}" class="active">
						<a href="#"><c th:text="${page_Num}"></c></a></li>
						
				<li th:if="${page_Num != pageInfo.pageNum }">
						<a th:href="@{${adss}+'?pn='+${page_Num }}">
						<c th:text="${page_Num}"></c></a></li>
				</span>

				<li th:if="${pageInfo.hasNextPage }">
					<a th:href="@{${adss}+'?pn='+${pageInfo.pageNum+1}}">
					<c aria-hidden="true">&raquo;</c></a></li>

				<li><a th:href="@{${adss}+'?pn='+${pageInfo.pages}}">末页</a></li>
				
			</ul>
		</div>
		
		<c
				th:if="${session.user.role} == administrator or ${session.user.role} == admin">
			<div class="mybtn">
				<a th:href="@{/integral/addInte.do}" />
				<button class="btn btn-default">录入积分</button>
				</a><span></span> <input type="button" name="cancel" id="cancel"
					value="删除积分" class="btn btn-default" />
			</div>
			</c>
	</div>
	<!-- 修改模态框 -->
	<div class="modal fade" id="myModal" tabindex="-1">
		<!--淡入淡出在最外层添加-->
		<!--窗口声明-->
		<div class="modal-dialog modal-md">
			<!--小窗口在窗口声明处添加-->
			<!-- modal-content 内容声明 -->
			<div class="modal-content">
				<!--头部-->
				<div class="modal-header">
					<button class="close" data-dismiss="modal">
						<span>&times;</span>
					</button>
					<h4 class="modal-title">修改积分信息</h4>
				</div>
				<!--主体-->
				<div class="modal-body">
					<div class="container container-width">
						<div class="title">
							<h2>
								<small>按照提示输入信息</small>
							</h2>
						</div>
						<form class="form-horizontal" role="form" id="form-horizontal">
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">姓名</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="studentName"
										value="" name="studentName" readonly="readonly"><input
										type="hidden" class="form-control" id="integralId" value=""
										placeholder="请输入ID" name="integralId">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">学号</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="studentId" value=""
										name="studentId" readonly="readonly">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">班级</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="grades" value=""
										name="grades" readonly="readonly">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">积分</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="score" value=""
										name="score" placeholder="请输入积分" required="required">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">原因</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="reason" value=""
										name="reason" placeholder="请输入原因" required="required">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">时间</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="time" value=""
										name="time" placeholder="请输入时间" required="required">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">部室</label>
								<div class="col-sm-9">
									<select name="clubroom" class="form-control"
										style="width:200px">
										<option id="clubroom"></option>
										<option th:each="club:${allRoom}"
											th:text="${club.clubroomName}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">学期</label>
								<div class="col-sm-9">
									<select name="intSemester" class="form-control"
										style="width:200px">
										<option id="intSemester"></option>
										<option th:each="semester:${allSemester}"
											th:text="${semester.semesterName}"></option>
									</select>
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">录入时间</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="creatime" value=""
										name="creatime" readonly="readonly">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">修改时间</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="getBookTime"
										value="" name="updateTime" readonly="readonly">
								</div>
							</div>
							<div class="form-group">
								<label for="firstname" class="col-sm-3 control-label">录入者</label>
								<div class="col-sm-9">
									<input type="text" class="form-control" id="name" value=""
										name="name" readonly="readonly">
								</div>
							</div>

						</form>
					</div>
				</div>
				<!--注脚-->
				<div class="modal-footer">
					<button id="updateIntegral" type="submit"
						class="btn btn-default btn-primary">确认</button>
				</div>
			</div>
		</div>
	</div>


	<script th:src="@{/static/js/jquery.min.js}" type="text/javascript"
		charset="utf-8"></script>
	<script th:src="@{/static/js/bootstrap.min.js}" type="text/javascript"
		charset="utf-8"></script>
	<script th:inline="javascript">
		window.onload = function(){
					function getDate(){
					debugger;
					 var today = new Date(); 
					 var date; 
					 date = (today.getFullYear()) +"-" + (today.getMonth() + 1 ) + "-" + today.getDate(); 
					 return date;
					 }
					 window.setInterval(function(){
					 document.getElementById("getBookTime").value=getDate();
					 }, 1000);
				}
	
		$(function() {
			$('#all').click(function() {
				if (this.checked) {
					$('.first :checkbox').prop("checked", true)
				} else {
					$('.first :checkbox').prop("checked", false)
				}
			});
		})
	
		$('#myModal').modal({
			backdrop : 'static',
			show : false
		});
		var bg = document.getElementsByClassName("bg")[0];
		$("button").click(function() {
			bg.style.display = "block";
		});
		$(".close").click(function() {
			bg.style.display = "none";
		})
		//点击修改，填充信息
		$('.edit').click(function() {
			$('#myModal').modal("show");
			var integralId = $(this).parent().parent().find("td").eq(1).text();
			var studentName = $(this).parent().parent().find("td").eq(2).text();
			var studentId = $(this).parent().parent().find("td").eq(3).text();
			var grades = $(this).parent().parent().find("td").eq(4).text();
			var score = $(this).parent().parent().find("td").eq(5).text();
			var reason = $(this).parent().parent().find("td").eq(6).text();
			var time = $(this).parent().parent().find("td").eq(7).text();
			var clubroom = $(this).parent().parent().find("td").eq(8).text();
			var intSemester = $(this).parent().parent().find("td").eq(9).text();
			var t = intSemester.trim();
			var creatime = $(this).parent().parent().find("td").eq(10).text();
			var name = $(this).parent().parent().find("td").eq(12).text();
			$("#integralId").val(integralId);
			$("#studentName").val(studentName);
			$("#studentId").val(studentId);
			$("#grades").val(grades);
			$("#score").val(score);
			$("#reason").val(reason);
			$("#time").val(time);
			$("#clubroom").val(clubroom);
			$("#clubroom").text(clubroom);
			$("#intSemester").text(intSemester);
			$("#intSemester").val(intSemester);
			$("#creatime").val(creatime);
			$("#name").val(name);
	
		})
	
		//点击修改，提交ajax
		$(document).on("click", "#updateIntegral", function() {
			//发送ajax请求保存更新的数据
					$.ajax({
						url : "updateIntegral.do",
						type : "PUT",
						data : $("#form-horizontal").serialize(),
						success : function(meg) {
							if(meg == "ok") {
								alert("修改成功");
								window.location.reload();
							}else{
								alert("修改失败！");
							}
							
						}
					}); 
				}); 
	
		//单个删除
		$(document).on("click", ".delete", function() {
			//1、弹出是否确认删除对话框
			var Name = $(this).parents("tr").find("td:eq(2)").text();
			var Id = $(this).parents("tr").find("td:eq(1)").text();
			if (confirm("确认删除【" + Name + "】吗？")) {
				$.ajax({
					url : "deleteIntegral.do",
					type : 'post',
					data : {
						ids : Id
					},
					contentType : 'application/x-www-form-urlencoded', //contentType很重要
					success : function() {
						alert("删除成功");
						window.location.reload();
					}
				});
			}
		});
	
		//点击全部删除，就批量删除
		$(document).on("click", "#cancel", function() {
			var Names = "";
			var del_idstr = "";
			$.each($(".first :checked"), function() {
				//this
				Names += $(this).parents("tr").find("td:eq(2)").text() + ",";
				//组装id字符串
				del_idstr += $(this).parents("tr").find("td:eq(1)").text() + "-";
			});
			//去除empNames多余的,
			Names = Names.substring(0, Names.length - 1);
			//去除删除的id多余的-
			del_idstr = del_idstr.substring(0, del_idstr.length - 1);
			if (confirm("确认删除【" + Names + "】吗？")) {
				//发送ajax请求删除
				$.ajax({
					url : 'deleteIntegral.do',
					type : "post",
					data : {
						ids : del_idstr
					},
					success : function() {
						alert("成功！！！");
						window.location.reload();
					}
				});
			}
		});
	</script>
</body>
</html>
